
Partial Class GTSWeb_Shipment_AddItems
    Inherits System.Web.UI.Page

    Private ReferenceNumber As Integer

    Protected Sub lnkAddItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkAddItem.Click
        Dim Description As String
        Dim Weight, Height, Length, Width As Double

        Dim RowsAffected As Integer
        Dim ItemsMgs As New GTSSystem.BLL.ShipmentItems
        Try
            Description = txtDescription.Text
            Weight = Convert.ToDouble(txtWeight.Text)
            Height = Convert.ToDouble(txtHeight.Text)
            Length = Convert.ToDouble(txtLength.Text)
            Width = Convert.ToDouble(txtWidth.Text)
            RowsAffected = ItemsMgs.AddShipmentItem(ReferenceNumber, Description, Weight, Length, Height, Width)
            If (RowsAffected = 1) Then
                Response.Redirect(Request.Url.ToString, False)
                lblMessage.Text = "Item successfully added to the database"
            End If
        Catch ex As Exception
            lblMessage.Text = "System Error <br/>" + "Invalid data provided. " + ex.GetHashCode.ToString
        End Try
    End Sub

 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Try
            ReferenceNumber = Convert.ToInt32(Request.QueryString("ReferenceNumber"))

        Catch ex As Exception
            lblError.Text = "System Error<br/>" + ex.Message + "<br/>" + ex.StackTrace
        End Try
  
    End Sub

    Protected Sub GridView1_RowDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles GridView1.RowDeleted
        Try
            Dim Shipmentmgr As New GTSSystem.BLL.Shipment
            Dim ItemsMgr As New GTSSystem.BLL.ShipmentItems
            Dim TotalItems As Integer = ItemsMgr.getShipmentTotalItems(ReferenceNumber)
            Dim TotalWeight As Double = ItemsMgr.getShipmentTotalWeight(ReferenceNumber)
            Shipmentmgr.UpdateItemsandWeightShipment(ReferenceNumber, TotalItems, TotalWeight)
            Response.Redirect(Request.Url.ToString, False)
        Catch ex As Exception
            lblError.Text = "System Error<br/>" + ex.Message + "<br/>" + ex.StackTrace
        End Try
    End Sub

    Protected Sub GridView1_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles GridView1.RowUpdated
        Response.Redirect(Request.Url.ToString, False)
    End Sub
End Class
